package net.aetherial.context.grounding.estimators;

import java.util.*;

/**
 * Generates an estimate based on the count of clarification-seeking behavior identified in the current conversation.
 */

public class ClarificationEstimator extends Estimator
{
	private static List<String> questionWords;
	
	static 
	{
		questionWords = new ArrayList<String> ();
		
		questionWords.add ("who");
		questionWords.add ("what");
		questionWords.add ("when");
		questionWords.add ("where");
		questionWords.add ("why");
		questionWords.add ("how");
		questionWords.add ("do");
		questionWords.add ("did");
		questionWords.add ("does");
	}
	
	private double count;
	
	/**
	 * @see net.aetherial.context.grounding.estimators.Estimator#reset()
	 */
	public void reset ()
	{
		count = 0.0;
	}
	
	/**
	 * Constructor.
	 */
	
	public ClarificationEstimator ()
	{
		count = 0.0;
	}

	/**
	 * @see net.aetherial.context.grounding.estimators.Estimator#estimate(java.lang.String, java.lang.String, double)
	 */
	
	public double estimate (String sender, String contribution, double score)
	{
		double increase = 0.0;
		
		int questionIndex = contribution.indexOf ("?");
		
		if (questionIndex != -1)
		{
			increase = 0.5;
			
			for (String word: questionWords)
			{
				int wordIndex = contribution.indexOf (word);
				
				if (wordIndex < questionIndex && increase < 1.0)
					increase =  1.0;
			}
		}
		
		count += increase;

		return count;
	}

	/**
	 * Returns "ClarificationEstimator".
	 * 
	 * @see net.aetherial.context.grounding.estimators.Estimator#getName()
	 */
	
	public String getName () 
	{
		return ("ClarificationEstimator");
	}
}
